<template>
	<view v-if="cart.length>0">
		<my-address></my-address>
		<view class="cart-title">
			<uni-icons type="shop" size="18"></uni-icons>
			<text class="cart-title-text">购物车</text>
		</view>
		<!-- 商品列表渲染 -->
		<uni-swipe-action>

			<block v-for="goods in cart" :key="goods.goods_id">
				<uni-swipe-action-item :right-options="options" @click="delGoods(goods.goods_id)">
					<my-goods :goods="goods" showRadio @radio-change="radioClickHandler" showNumber
						@changeFn="changeFn">
					</my-goods>
				</uni-swipe-action-item>
			</block>

		</uni-swipe-action>
		<view class="cart-container">
			<my-settle></my-settle>
		</view>

	</view>

	<view v-else>

		空空如也
	</view>
</template>
<script>
	import badgeMixin from '../../mxins/tabbar-badge.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		mixins: [badgeMixin],
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}],
				value: 0,
			};
		},
		computed: {
			...mapState('cart', ['cart'])
		},
		methods: {
			...mapMutations('cart', ['updataGoodsSate', 'changeGoodsCount', 'delGoodsById']),
			radioClickHandler(e) {
				this.goods = e
				this.updataGoodsSate(e)
			},
			changeFn(value) {
				// this.setBadge()
				this.changeGoodsCount(value)
				// this.value = value
				// uni.setTabBarBadge({
				// 	index: 2,
				// 	text: value.goods_count + ''
				// })
			},
			delGoods(id) {
				this.delGoodsById(id)
			}

		},


	}
</script>
<style lang="scss">
	.cart-title {
		height: 40px;
		display: flex;
		align-items: center;
		font-size: 14px;
		padding-left: 5px;
		border-bottom: 1px solid #efefef;

		.cart-title-text {
			margin-left: 10px;
		}
	}

	.cart-container {
		padding-bottom: 50px;
	}
</style>
